﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RüdigerZeichnen
{
    public partial class Form1 : Form
    {
        int x1 = 0;
            int x2 = 0;
            int y1 = 0;
            int y2 = 0;
            int iPlayer = 1;
            int iZeichnen = 0;
            Graphics grafik;
        
        public Form1()
        {
            InitializeComponent();
            lbMaus.Text = "Aus";
            CreateGraphics();
        }

        private void btstart_Click(object sender, EventArgs e)
        {
            
            Rectangle rechteck = new Rectangle(20/*x-Koordinaten(nach unten)*/, 35/*y-Koordinaten(nach rechts)*/,
                200/*Länge*/, 200/*Breite*/);//Fläche für Zeichnung
            grafik.DrawEllipse(Pens.Black, rechteck);//Schwarzer Kreis
            grafik.DrawRectangle(Pens.Red, rechteck);//Rotes Rechteck

        }

        private void btFormen_Click(object sender, EventArgs e)
        {
            
            
            Rectangle Vorderrad = new Rectangle(40, 120, 50, 50);
            grafik.DrawEllipse(Pens.Black, Vorderrad);
        }

        private void btHinten_Click(object sender, EventArgs e)
        {
            
            Rectangle Vorderrad = new Rectangle(110, 120, 50, 50);
            grafik.DrawEllipse(Pens.Black, Vorderrad);
        }

        private void btTic_Click(object sender, EventArgs e)
        {
            BtTic.Text = tBoxName.Text;
            //int iPlayer = Convert.ToInt32(tBoxPlayer.Text);
            lbPlayer.Text = Convert.ToString(iPlayer);
            int iFeld = 1;
                try{iFeld=Convert.ToInt32(tBoxFeld.Text);}
                    catch(Exception)
                {}
                grafik = CreateGraphics();
            switch(iFeld)//welches Feld gewählt wurde
            {
            case 1:
                    Rectangle Feld1 = new Rectangle(40, 120, 50, 50);//wo sich das Feld befindet
                    switch (iPlayer)
                    {
                        case 1:

                            grafik.DrawRectangle(Pens.Red, Feld1);
                            break;
                        case 2:
                            grafik.DrawEllipse(Pens.Black, Feld1);
                            break;
                        default:

                            break;            }
            break;
                case 2:
                    Rectangle Feld2 = new Rectangle(110, 120, 50, 50);
                    switch (iPlayer)//welches Zeichen Gewählt wurde
                    {
                        case 1:
                            
                            grafik.DrawRectangle(Pens.Red, Feld2);
                            break;
                        case 2:
                            grafik.DrawEllipse(Pens.Black, Feld2);
                            break;
                        default:
                       
                            break;
                    }
                    break;
                    case 3:Rectangle Feld3 = new Rectangle(190, 120, 50, 50);
                    switch (iPlayer)
                    {
                        case 1:

                            grafik.DrawRectangle(Pens.Red, Feld3);
                            break;
                        case 2:
                            grafik.DrawEllipse(Pens.Black, Feld3);
                            break;
                        default:

                            break;
                    }break;
                    case 4: Rectangle Feld4 = new Rectangle(40, 210, 50, 50);
                        switch (iPlayer)
                        {
                            case 1:

                                grafik.DrawRectangle(Pens.Red, Feld4);
                                break;
                            case 2:
                                grafik.DrawEllipse(Pens.Black, Feld4);
                                break;
                            default:

                                break;
                        } break;
                    case 5: Rectangle Feld5 = new Rectangle(110, 210, 50, 50);
                        switch (iPlayer)
                        {
                            case 1:

                                grafik.DrawRectangle(Pens.Red, Feld5);
                                break;
                            case 2:
                                grafik.DrawEllipse(Pens.Black, Feld5);
                                break;
                            default:

                                break;
                        } break;
                    case 6: Rectangle Feld6 = new Rectangle(190, 210, 50, 50);
                        switch (iPlayer)
                        {
                            case 1:

                                grafik.DrawRectangle(Pens.Red, Feld6);
                                break;
                            case 2:
                                grafik.DrawEllipse(Pens.Black, Feld6);
                                break;
                            default:

                                break;
                        } break;
                    case 7: Rectangle Feld7 = new Rectangle(40, 300, 50, 50);
                        switch (iPlayer)
                        {
                            case 1:

                                grafik.DrawRectangle(Pens.Red, Feld7);
                                break;
                            case 2:
                                grafik.DrawEllipse(Pens.Black, Feld7);
                                break;
                            default:

                                break;
                        } break;
                    case 8: Rectangle Feld8 = new Rectangle(110, 300, 50, 50);
                        switch (iPlayer)
                        {
                            case 1:

                                grafik.DrawRectangle(Pens.Red, Feld8);
                                break;
                            case 2:
                                grafik.DrawEllipse(Pens.Black, Feld8);
                                break;
                            default:

                                break;
                        } break;
                    case 9: Rectangle Feld9 = new Rectangle(190, 300, 50, 50);
                        switch (iPlayer)
                        {
                            case 1:

                                grafik.DrawRectangle(Pens.Red, Feld9);
                                break;
                            case 2:
                                grafik.DrawEllipse(Pens.Black, Feld9);
                                break;
                            default:

                                break;
                        } break;
                        
            }if (iPlayer == 2)
                        { iPlayer = 1; }
                        else { iPlayer = 2; }
        

        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (iZeichnen == 1)
            {
                x2 = e.X;
                y2 = e.Y;
                

                int x1 = Math.Min(this.x1, this.x2);
                int y1 = Math.Min(this.y1, this.y2);
                x2 = Math.Max(this.x1, this.x2);
                y2 = Math.Max(this.y1, this.y2);

                /*
                if (x2-x1 < 0)
                { 
                    int x3 = x1;
                    x1 = x2;
                    x2 = x3;
                }
                if (y2 - y1 < 0)
                {
                    int y3 = y1;
                    y1 = y2;
                    y2 = y3;
                }
                 * */
                Rectangle Maus = new Rectangle(x1, y1, x2 - x1, y2 - y1);
                grafik.DrawRectangle(Pens.Black, Maus);
            }

        }

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            x1 = e.X;
y1 = e.Y;
        }

        private void btMaus_Click(object sender, EventArgs e)
        {
            
            if (iZeichnen == 1)
            { iZeichnen = 0;
            lbMaus.Text = "Aus";
            }
            else {iZeichnen = 1;
            lbMaus.Text = "Ein";
            }
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (iZeichnen == 1)
            {
                x2 = e.X;
                y2 = e.Y;
                

                int x1 = Math.Min(this.x1, this.x2);
                int y1 = Math.Min(this.y1, this.y2);
                x2 = Math.Max(this.x1, this.x2);
                y2 = Math.Max(this.y1, this.y2);
                Rectangle Maus = new Rectangle(x1, y1, x2 - x1, y2 - y1);
                grafik.DrawRectangle(Pens.Black, Maus);
            }
        }
       
    }
}
